import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.LayoutManager;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;

import java.awt.CardLayout;

import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import java.awt.Font;

import javax.swing.JTabbedPane;
import javax.swing.JRadioButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Acomp extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField txtPwd;
	private JTextField txtUid;
	private JButton loginBtn;
	private JButton joinBtn;
	private JTextField textField;
	private final CardLayout cards = new CardLayout(0,0); //1
	private final JPanel myPane = new JPanel();
	private final JTabbedPane mianPane = new JTabbedPane(JTabbedPane.TOP);
	

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Acomp dialog = new Acomp();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Acomp() {
		setTitle(":: 고급 컴퍼넌트 ::");
		setBounds(100, 100, 640, 480);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(new BorderLayout(0, 0));
		{
			JPanel panel = new JPanel();
			panel.setPreferredSize(new Dimension(10, 120));
			contentPanel.add(panel, BorderLayout.NORTH);
			panel.setLayout(new BorderLayout(0, 0));
			{
				JPanel top = new JPanel();
				top.setPreferredSize(new Dimension(400, 10));
				panel.add(top, BorderLayout.WEST);
				{
					JLabel topLogo = new JLabel("New label");
					topLogo.setIcon(new ImageIcon(Acomp.class.getResource("/cho114366/swing/background/top.jpg")));
					top.add(topLogo);
				}
			}
			{
				
				final JPanel cardPane = new JPanel();
				cardPane.setPreferredSize(new Dimension(210, 10));
				panel.add(cardPane, BorderLayout.EAST);
				cardPane.setLayout(cards);                                                //2
				{
					JPanel loginPane = new JPanel();
					loginPane.setToolTipText("");
					cardPane.add(loginPane, "login");
					{
						txtUid = new JTextField();
						txtUid.setFont(new Font("굴림", Font.ITALIC, 12));
						txtUid.setText("아이디");
						txtUid.setColumns(10);
					}
					{
						loginBtn = new JButton("로그인");
						loginBtn.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent e) {
								if(txtUid.getText().equals("abc")&&txtPwd.getText().equals("12345"))
									//if(txtPwd.getText().equals("12345"))
								{cards.show(cardPane,"logout");
								JOptionPane.showMessageDialog(null, "myPane 옵션이 활성화됩니다.");
								mianPane.setEnabledAt(2,true);}
								// 탭활성 / 비활성은
								// setEnableAt()을 이용
								// 3번째 탭을 비활성함
								else JOptionPane.showMessageDialog(null,"잘못입력하였습니다");
					
								// cards : 레이아웃
								// cardPane : 카드 레이아웃이 적용된 패널
								// logout : cardPane에 보여줄 패널 이름
							}
						});
					}
					{
						txtPwd = new JTextField();
						txtPwd.setFont(new Font("굴림", Font.ITALIC, 12));
						txtPwd.setText("비밀번호");
						txtPwd.setColumns(10);
					}
					{
						joinBtn = new JButton("회원가입");
					}
					GroupLayout gl_loginPane = new GroupLayout(loginPane);
					gl_loginPane.setHorizontalGroup(
						gl_loginPane.createParallelGroup(Alignment.LEADING)
							.addGroup(Alignment.TRAILING, gl_loginPane.createSequentialGroup()
								.addGap(11)
								.addGroup(gl_loginPane.createParallelGroup(Alignment.LEADING, false)
									.addComponent(txtUid, 0, 0, Short.MAX_VALUE)
									.addComponent(txtPwd, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE))
								.addPreferredGap(ComponentPlacement.RELATED)
								.addGroup(gl_loginPane.createParallelGroup(Alignment.TRAILING)
									.addComponent(loginBtn, GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
									.addComponent(joinBtn, GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
								.addContainerGap())
					);
					gl_loginPane.setVerticalGroup(
						gl_loginPane.createParallelGroup(Alignment.LEADING)
							.addGroup(Alignment.TRAILING, gl_loginPane.createSequentialGroup()
								.addContainerGap(30, Short.MAX_VALUE)
								.addGroup(gl_loginPane.createParallelGroup(Alignment.BASELINE)
									.addComponent(txtUid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
									.addComponent(loginBtn))
								.addGap(17)
								.addGroup(gl_loginPane.createParallelGroup(Alignment.BASELINE)
									.addComponent(txtPwd, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
									.addComponent(joinBtn))
								.addGap(27))
					);
					loginPane.setLayout(gl_loginPane);
				}
				{
					JPanel logoutPane = new JPanel();
					cardPane.add(logoutPane, "logout");
					
					JLabel myNick = new JLabel(" 천송이");
					myNick.setFont(new Font("굴림", Font.BOLD, 18));
					JButton logoutBtn = new JButton("로그 아웃");
					logoutBtn.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent e) {
							cards.show(cardPane, "login");
						}
					});
					JLabel myAvatar = new JLabel("");
					myAvatar.setIcon(new ImageIcon(Acomp.class.getResource("/cho114366/swing/icon/icon2.png")));
					GroupLayout gl_logoutPane = new GroupLayout(logoutPane);
					gl_logoutPane.setHorizontalGroup(
						gl_logoutPane.createParallelGroup(Alignment.LEADING)
							.addGroup(gl_logoutPane.createSequentialGroup()
								.addContainerGap()
								.addComponent(myAvatar, GroupLayout.PREFERRED_SIZE, 61, GroupLayout.PREFERRED_SIZE)
								.addGap(28)
								.addGroup(gl_logoutPane.createParallelGroup(Alignment.LEADING)
									.addComponent(logoutBtn)
									.addComponent(myNick, GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))
								.addContainerGap())
					);
					gl_logoutPane.setVerticalGroup(
						gl_logoutPane.createParallelGroup(Alignment.LEADING)
							.addGroup(Alignment.TRAILING, gl_logoutPane.createSequentialGroup()
								.addContainerGap(10, Short.MAX_VALUE)
								.addGroup(gl_logoutPane.createParallelGroup(Alignment.TRAILING)
									.addGroup(gl_logoutPane.createSequentialGroup()
										.addComponent(myNick, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
										.addGap(18)
										.addComponent(logoutBtn))
									.addComponent(myAvatar))
								.addGap(25))
					);
					logoutPane.setLayout(gl_logoutPane);
				}
			}
		}
		{
			
			contentPanel.add(mianPane, BorderLayout.CENTER);
			{
				JPanel baseFind = new JPanel();
				mianPane.addTab("기본검색", new ImageIcon(Acomp.class.getResource("/cho114366/swing/menu/exit.png")), baseFind, null);
				{
					JButton btnNewButton = new JButton("New button");
					baseFind.add(btnNewButton);
				}
			}
			{
				JPanel detailFind = new JPanel();
				mianPane.addTab("상세검색", new ImageIcon(Acomp.class.getResource("/cho114366/swing/menu/new.png")), detailFind, null);
				{
					textField = new JTextField();
					detailFind.add(textField);
					textField.setColumns(10);
				}
			}
			{
				
				mianPane.addTab("My page", new ImageIcon(Acomp.class.getResource("/cho114366/swing/menu/close.png")), myPane, null);
				mianPane.setEnabledAt(2, false);
				{
					JRadioButton rdbtnNewRadioButton = new JRadioButton("New radio button");
					myPane.add(rdbtnNewRadioButton);
				}
			}
		}
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
	}
}
